var main = {};
var myScroll;
(function ($) {
	
    main.init = function () {
        document.addEventListener('touchmove', function (e) {
            e.preventDefault();
        }, false);
    };

    /**
     * @func move()
     * @desc 监听滚动条的位置，异步加载列表
     */
    function move() {
        if (this.y < main.max - 80) {
            $("#tip").hide();
            $("#loading").show();
            var maxid=$(".details li:last").val();
            var categoryId=$("#categoryId").val();
            var html = "";
            $.ajax({
        		type:"post",
        		async:true, 
	        	url:path+"/article/articlemove/"+categoryId+"?id="+maxid,
        		success:function(resultjson){	
        			if('200' == resultjson.code){
        				var html = "";
        				for (var i = 0; i < resultjson.result.length; i++) {
        					 html += '<li  value="'+resultjson.result[i].id+'"><a href='+path+'/article/articleinfo/'+resultjson.result[i].id+'><div class="detailsImg"><img src="'+resultjson.result[i].picurl+'"></div><h3>'+resultjson.result[i].title+'</h3></div></a></li>'
        					 $("#id").val(resultjson.result[resultjson.result.length-1].id);
        				}	
        				$(".details").append(html);
        				if(resultjson.result.length>=20){
 	  		            	$("#loading").hide();
 			  	            $("#tip").show();
 	  		            }else{
 	  		            	$("#loading").hide();
 	  		            	$("#tip").hide();
 	  		            }
        			}
        		}
        	})
            this.refresh();
            main.max = this.maxScrollY;
            console.log(main.max);
            $("#loading").hide();
            $("#tip").show();
        }
    }

    /**
     * @func main.scroll()
     * @desc 配置iscroll插件
     */
    main.scroll = function () {
        myScroll = new IScroll(".wrapper", {probeType: 3, mouseWheel: true, click: true, preventDefault: false});

        main.max = myScroll.maxScrollY;
        console.log(main.max);

        myScroll.on("scroll", move);
    }
})(jQuery);

main.init();

window.onload = function () {
    main.scroll();
};
